﻿--[[	$Id: oUF_cMenu.lua 2587 2012-09-23 20:35:29Z sdkyron@gmail.com $	]]

local _, oUF_Caellian = ...

local Dropdown = CreateFrame("Frame", "oUF_CaellianUnitDropDownMenu", UIParent, "UIDropDownMenuTemplate")

local Menu = function(self)
    Dropdown:SetParent(self)
    return ToggleDropDownMenu(1, nil, Dropdown, "cursor", 0, 0)
end

local Init = function(self)
    local unit = self:GetParent().unit
    local Menu, name, id

    if not unit then
        return
    end

    if UnitIsUnit(unit, "player") then
        Menu = "SELF"
    elseif UnitIsUnit(unit, "vehicle") then
        Menu = "VEHICLE"
    elseif UnitIsUnit(unit, "pet") then
        Menu = "PET"
    elseif UnitIsPlayer(unit) then
        id = UnitInRaid(unit)
        if id then
            Menu = "RAID_PLAYER"
            name = GetRaidRosterInfo(id)
        elseif UnitInParty(unit) then
            Menu = "PARTY"
        else
            Menu = "PLAYER"
        end
    else
        Menu = "TARGET"
        name = RAID_TARGET_ICON
    end

    if Menu then
        UnitPopup_ShowMenu(self, Menu, unit, name, id)
    end
end

UIDropDownMenu_Initialize(Dropdown, Init, "Menu")

oUF_Caellian.Menu = Menu